<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>mixin混合模式使用</title>
  </head>
  <body></body>
  <script>
    let Tool = {
      max(key) {
        return this.data.sort((a, b) => b[key] - a[key])[0];
      }
    };
    let Total = {
      count(key) {
        return this.data.reduce((t, c) => t + c[key], 0);
      }
    };
    const data = [
      { name: "js", price: 100, click: 189 },
      { name: "mysql", price: 212, click: 172 },
      { name: "vue.js", price: 98, click: 89 }
    ];
    class Lesson {
      constructor(lessons) {
        this.lessons = lessons;
      }
      get data() {
        return this.lessons;
      }
    }
    Object.assign(Lesson.prototype, Tool, Total);
    console.dir(Lesson);
    let hd = new Lesson(data);
    console.log(hd.max("click"));
    console.log(hd.count("price"));
  </script>
</html>
